package com.jic.market.impl.allocation;

import com.jic.common.base.vo.enums.DeptTypeEnums;
import com.jic.market.common.enums.CostAllocationFlagEnum;
import com.jic.market.entity.AllocationModel;
import com.jic.market.entity.LotteryTheme;
import com.jic.market.request.after.TellAddAllocationRequest;
import com.jic.market.service.LotteryActivityService;
import com.jic.market.service.allocation.PromotionAddAllocationStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author xuyongliang
 * @version V1.0
 * @className PromotionAddAllocationStrategyLottery
 * @description 抽奖分摊策略
 * @date 2020/3/16
 */
@Slf4j
@Service("allocationLottery")
public class PromotionAddAllocationStrategyLottery implements PromotionAddAllocationStrategy {

    @Resource
    private LotteryActivityService lotteryActivityService;

    @Override
    public AllocationModel collectionAllocation(TellAddAllocationRequest request) {
        log.info("--------进入抽奖分摊策略tellRequest--{}-----",request);
        // 转成 long 类型
        Long promotionId =Long.valueOf(request.getPromotionId());
        LotteryTheme lotteryTheme = lotteryActivityService.queryByPrimaryKey(promotionId);

        // CostAllocationFlagEnum.SHARE.getCode().equals(lotteryTheme.getCostAllocationFlag())
        AllocationModel model =new AllocationModel();
        BeanUtils.copyProperties(lotteryTheme, model);

        //不分摊则判断当前活动组织等级设置默认值100
        if (lotteryTheme.getDeptType() == DeptTypeEnums.OPERATION_PLATFORM.getCode()){
            model.setParentAllocationScale(100);
        }else if (lotteryTheme.getDeptType() == DeptTypeEnums.CHILD_PLATFORM.getCode()){
            model.setChildAllocationScale(100);
        }else if (lotteryTheme.getDeptType() == DeptTypeEnums.MERCHANT_PLATFORM.getCode()){
            model.setMerchantAllocationScale(100);
        }else {
            model.setStoreAllocationScale(100);
        }
        model.setPromotionId(lotteryTheme.getPromotionCode());
        model.setPromName(lotteryTheme.getActivityName());
        model.setStartTime(lotteryTheme.getEffStartTime());
        model.setEndTime(lotteryTheme.getEffEndTime());
        model.setDeptId(lotteryTheme.getDeptId());
        // 取自  抽奖促销表 deptType
        model.setDeptType(lotteryTheme.getDeptType());
        model.setPromType(lotteryTheme.getFrontPromotionType());

        return model;

    }
}
